//
//  RegisterAgreementAlertView.m
//  PigMarket
//
//  Created by mac on 2019/7/31.
//  Copyright © 2019 pigmarket.oc. All rights reserved.
//

#import "RegisterAgreementAlertView.h"


@interface RegisterAgreementAlertView ()
/**
 内容text
 */
@property (nonatomic , strong) YYLabel *contentText;
/**
 注册协议 和  隐私政策
 */
@property (nonatomic , strong) YYLabel *detailAgreement;
@end
@implementation RegisterAgreementAlertView

#pragma mark - init method
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self initView];
        [self initLayout];
    }
    return self;
}

- (void)initView {
    // 添加子控件
    [self addSubview:self.contentText];
    [self addSubview:self.detailAgreement];
}

- (void)initLayout {
    // 布局子控件
    [self.contentText mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.mas_equalTo(0);
        make.height.mas_equalTo(154);
    }];
    [self.detailAgreement mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(0);
        make.top.mas_equalTo(self.contentText.mas_bottom).offset(30);
        make.height.mas_equalTo(50);
        make.bottom.mas_equalTo(0);
    }];
}

#pragma mark - getter and setter
- (YYLabel *)contentText {
    if (!_contentText) {
        _contentText = [[YYLabel alloc] init];
        _contentText.numberOfLines = 0;
        NSString *textStr = @"在您注册成为豚集用户的过程中，您需要完成我们的注册流程并通过点击同意的形式在线签署以下协议，请您务必仔细阅读、充分理解协议中的条款内容后再点击同意（尤其是以粗体并下划线标识的条款，因为这些条款可能会明确您应履行的义务或对您的权利有所限制";
        NSMutableAttributedString *text = [[NSMutableAttributedString alloc] initWithString:textStr];
        text.yy_font = [UIFont systemFontOfSize:13];
        text.yy_color = [UIColor colorWithHexString:@"#808080"];
        text.yy_lineSpacing = 13;
        _contentText.attributedText = text;
    }
    return _contentText;
}
- (YYLabel *)detailAgreement {
    if (!_detailAgreement) {
        _detailAgreement = [[YYLabel alloc] init];
        _detailAgreement.numberOfLines = 0;
        NSString *textStr = @"点击同意即表示您已阅读并同意《豚集用户注册协议》与《豚集隐私政策》";
        NSMutableAttributedString *text = [[NSMutableAttributedString alloc] initWithString:textStr];
        text.yy_font = [UIFont systemFontOfSize:13];
        text.yy_color = [UIColor colorWithHexString:@"#808080"];
        text.yy_lineSpacing = 13;
        @weakify(self);
        [text yy_setTextHighlightRange:NSMakeRange(14, 10) color:[UIColor primaryColor] backgroundColor:[UIColor clearColor] tapAction:^(UIView * _Nonnull containerView, NSAttributedString * _Nonnull text, NSRange range, CGRect rect) {
            PMLog(@"《豚集用户注册协议》");
            @strongify(self);
            if (self.registerAgreementBlock) {
                self.registerAgreementBlock();
            }
        }];
        [text yy_setTextHighlightRange:NSMakeRange(25, 8) color:[UIColor primaryColor] backgroundColor:[UIColor clearColor] tapAction:^(UIView * _Nonnull containerView, NSAttributedString * _Nonnull text, NSRange range, CGRect rect) {
            PMLog(@"《豚集隐私政策》");
            @strongify(self);
            if (self.privacyAgreementBlock) {
                self.privacyAgreementBlock();
            }
        }];
        _detailAgreement.attributedText = text;
    }
    return _detailAgreement;
}
@end
